package com.ccys.cms.service.administrator.impl;


import com.ccys.cms.service.administrator.TblSupportTabWebService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.administrator.TblSupportTabDTO;
import com.ccys.db.entity.TblSupportTab;
import com.ccys.db.mapper.TblSupportTabMapper;
import com.ccys.db.page.PageUtils;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.service.BaseTblAuditTrailWebService;
import com.ccys.db.vo.administrator.TblSupportTabWebVO;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * tbl_support_tab管理
 */
@Service
@Slf4j
public class TblSupportTabWebServiceImpl extends BaseServiceImpl<TblSupportTab> implements TblSupportTabWebService {

    @Autowired(required = false)
    private TblSupportTabMapper tblSupportTabMapper;
    @Autowired(required = false)
    private BaseTblAuditTrailWebService baseTblAuditTrailWebService;

    @Override
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, TblSupportTabDTO dto) {
        PageUtils.startPage(request);
        List<TblSupportTabWebVO> list = this.tblSupportTabMapper.listObjectsCms(dto);
        PageInfo pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }


    @Override
    public ResponseResult change(TblSupportTab entity) {
        if (StringUtils.isBlank(entity.getId())) {
            if(entity.getStatus() == null) {
                entity.setStatus(1);
            }
            // 新增
            this.saveEntity(entity);
        } else {
            // 编辑
            this.updateEntityById(entity);
            if(entity.getStatus() != null) {
                this.baseTblAuditTrailWebService.saveStatusLog(entity,entity.getStatus());
            }
        }
        return ResponseResult.success();
    }

    @Override
    public ResponseResult delete(TblSupportTab dto) {
        TblSupportTab entity = new TblSupportTab();
        entity.setId(dto.getId());
        entity.setDelFlag(1);
        this.updateEntityById(entity);
        return ResponseResult.success();
    }


}